<style lang="less">
.account-info-vue {
    padding: 30px 30px 30px 0;
    max-width: 500px;
}
</style>
<template>
    <div class="account-info-vue">
        <Form :model="acc" :rules="rules" ref="form" showErrorTip>
            <FormItem label="用户名" prop="username">
                <Input type="text" v-model="acc.username" />
            </FormItem>
            <FormItem label="密码" prop="password">
                <Input type="password" v-model="acc.password" />
            </FormItem>
            <FormItem label="上级" prop="pid">
                <p style="width: 300px;display: flex;">
                    <TreePicker ref="treepicker" placeholder="无上级" v-model="acc.pid" :option="options" :use-confirm="useConfirm"
                        :disabled="disabled" @change="change" @choose="choose" @select="select" style="flex:1"/>
                    <Button @click="clearUP">无上级</Button>
                </p>
                
            </FormItem>
            <FormItem label="" prop="location">
                <Button color="primary" @click="save" :loading="saveloading">保存</Button>
                <Button @click="reset">重置</Button>
            </FormItem>
        </Form>
    </div>
</template>
<script>
import utils from '@common/utils';
import Request from '@common/request';
export default {
    props: {
        account: Object,
        users: Array,
        id: Number,
    },
    data() {
        let list = this.users
        return {
            param: {
                1: '账号',
                2: '资料',
            },
            options: {
                keyName: 'id',
                parentName: 'pid',
                titleName: 'username',
                dataMode: 'children',
                datas: list
            },
            selected: '1',
            acc: utils.copy(this.account),
            rules: {
                required: ['username', 'password'],
            },
            saveloading: false
        };
    },
    mounted() {
        this.init();
    },
    methods: {
        init() { },
        clearUP() {
            this.acc.pid = null
        },
        save() {
            if (!this.$refs.form.valid().result) return;
            this.saveloading = true;
            const param = utils.copy(this.acc)
            this.$emit('submit', param)
        },
        reset() {
            this.$refs.form.resetValid();
            this.acc = utils.copy(this.account);
        }
    },
    computed: {}
};
</script>
